home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
198_02
/
window.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-21
|
23KB
|
877 lines
/*
* Window management. Some of the functions are internal, and some are
* attached to keys that the user actually types.
*/
#include <stdio.h>
#include "estruct.h"
#include "edef.h"
#if ST520 & MEGAMAX
overlay "window"
#endif
/*
* Reposition dot in the current window to line "n". If the argument is
* positive, it is that line. If it is negative it is that line from the
* bottom. If it is 0 the window is centered (this is what the standard
* redisplay code does). With no argument it defaults to 0. Bound to M-!.
*/
reposition(f, n)
{
if (f == FALSE) /* default to 0 to center screen */
n = 0;
curwp->w_force = n;
curwp->w_flag |= WFFORCE;
return (TRUE);
}
/*
* Refresh the screen. With no argument, it just does the refresh. With an
* argument it recenters "." in the current window. Bound to "C-L".
*/
refresh(f, n)
{
if (f == FALSE)
sgarbf = TRUE;
else
{
curwp->w_force = 0; /* Center dot. */
curwp->w_flag |= WFFORCE;
}
return (TRUE);
}
/*
* The command make the next window (next => down the screen) the current
* window. There are no real errors, although the command does nothing if
* there is only 1 window on the screen. Bound to "C-X C-N".
*
* with an argument this command finds the <n>th window from the top
*
*/
nextwind(f, n)
int f, n; /* default flag and numeric argument */
{
register WINDOW *wp;
register int nwindows; /* total number of windows */
if (f) {
/* first count the # of windows */
wp = wheadp;
nwindows = 1;
while (wp->w_wndp != NULL) {
nwindows++;
wp = wp->w_wndp;
}
/* if the argument is negative, it is the nth window
from the bottom of the screen */
if (n < 0)
n = nwindows + n + 1;
/* if an argument, give them that window from the top */
if (n > 0 && n <= nwindows) {
wp = wheadp;
while (--n)
wp = wp->w_wndp;
} else {
mlwrite("Window number out of range");
return(FALSE);
}
} else
if ((wp = curwp->w_wndp) == NULL)
wp = wheadp;
curwp = wp;
curbp = wp->w_bufp;
upmode();
return (TRUE);
}
/*
* This command makes the previous window (previous => up the screen) the
* current window. There arn't any errors, although the command does not do a
* lot if there is 1 window.
*/
prevwind(f, n)
{
register WINDOW *wp1;
register WINDOW *wp2;
/* if we have an argument, we mean the nth window from the bottom */
if (f)
return(nextwind(f, -n));
wp1 = wheadp;
wp2 = curwp;
if (wp1 == wp2)
wp2 = NULL;
while (wp1->w_wndp != wp2)
wp1 = wp1->w_wndp;
curwp = wp1;
curbp = wp1->w_bufp;
upmode();
return (TRUE);
}
/*
* This command moves the current window down by "arg" lines. Recompute the
* top line in the window. The move up and move down code is almost completely
* the same; most of the work has to do with reframing the window, and picking
* a new dot. We share the code by having "move down" just be an interface to
* "move up". Magic. Bound to "C-X C-N".
*/
mvdnwind(f, n)
int n;
{
return (mvupwind(f, -n));
}
/*
* Move the current window up by "arg" lines. Recompute the new top line of
* the window. Look to see if "." is still on the screen. If it is, you win.
* If it isn't, then move "." to center it in the new framing of the window
* (this command does not really move "."; it moves the frame). Bound to
* "C-X C-P".
*/
mvupwind(f, n)
int n;
{
register LINE *lp;
register int i;
lp = curwp->w_linep;
if (n < 0)
{
while (n++ && lp!=curbp->b_linep)
lp = lforw(lp);
}
else
{
while (n-- && lback(lp)!=curbp->b_linep)
lp = lback(lp);
}
curwp->w_linep = lp;
curwp->w_flag |= WFHARD; /* Mode line is OK. */
for (i = 0; i < curwp->w_ntrows; ++i)
{
if (lp == curwp->w_dotp)
return (TRUE);
if (lp == curbp->b_linep)
break;
lp = lforw(lp);
}
lp = curwp->w_linep;
i = curwp->w_ntrows/2;
while (i-- && lp != curbp->b_linep)
lp = lforw(lp);
curwp->w_dotp = lp;
curwp->w_doto = 0;
return (TRUE);
}
/*
* This command makes the current window the only window on the screen. Bound
* to "C-X 1". Try to set the framing so that "." does not have to move on the
* display. Some care has to be taken to keep the values of dot and mark in
* the buffer structures right if the distruction of a window makes a buffer
* become undisplayed.
*/
onlywind(f, n)
{
register WINDOW *wp;
register LINE *lp;
register int i;
while (wheadp != curwp) {
wp = wheadp;
wheadp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
wp->w_bufp->b_fcol = wp->w_fcol;
}
free((char *) wp);
}
while (curwp->w_wndp != NULL) {
wp = curwp->w_wndp;
curwp->w_wndp = wp->w_wndp;
if (--wp->w_bufp->b_nwnd == 0) {
wp->w_bufp->b_dotp = wp->w_dotp;
wp->w_bufp->b_doto = wp->w_doto;
wp->w_bufp->b_markp = wp->w_markp;
wp->w_bufp->b_marko = wp->w_marko;
wp->w_bufp->b_fcol = wp->w_fcol;
}
free((char *) wp);
}
lp = curwp->w_linep;
i = curwp->w_toprow;
while (i-- > 0 && lback(lp) != curbp->b_linep)
lp = lback(lp);
curwp->w_toprow = 0;
curwp->w_ntrows = term.t_nrow - 1 - menuflag;
curwp->w_linep = lp;
curwp->w_flag |= WFMODE|WFHARD;
return (TRUE);
}
/*
* Delete the current window, placing its space in the window above,
* or, if it is the top window, the window below. Bound to C-X 0.
*/
delwind(f,n)
int f, n; /* arguments are ignored for this command */
{
register WINDOW *wp; /* window to recieve deleted space */
register WINDOW *lwp; /* ptr window before curwp */
register int target; /* target line to search for */
LINE *lp;
/* if there is only one window, don't delete it */
if (wheadp->w_wndp == NULL) {
mlwrite("Can not delete this window");
return(FALSE);
}
/* find window before curwp in linked list */
wp = wheadp;
lwp = NULL;
while (wp != NULL) {
if (wp == curwp)
break;
lwp = wp;
wp = wp->w_wndp;
}
/* find recieving window and give up our space */
wp = wheadp;
if (curwp->w_toprow == 0) {
/* find the next window down */
target = curwp->w_ntrows + 1;
while (wp != NULL) {
if (wp->w_toprow == target)
break;
wp = wp->w_wndp;
}
if (wp == NULL)
return(FALSE);
wp->w_toprow = 0;
wp->w_ntrows += target;
/* change starting location to keep dot on same screen line */
lp = wp->w_linep;
while (target-- > 0 && lback(lp) != wp->w_bufp->b_linep)
lp = lback(lp);
wp->w_linep = lp;
} else {
/* find the next window up */
target = curwp->w_toprow - 1;
while (wp != NULL) {
if ((wp->w_toprow + wp->w_ntrows) == target)
break;
wp = wp->w_wndp;
}
if (wp == NULL)
return(FALSE);
wp->w_ntrows += 1 + curwp->w_ntrows;
}
/* get rid of the current window */
if (--curwp->w_bufp->b_nwnd == 0) {
curwp->w_bufp->b_dotp = curwp->w_dotp;
curwp->w_bufp->b_doto = curwp->w_doto;
curwp->w_bufp->b_markp = curwp->w_markp;
curwp->w_bufp->b_marko = curwp->w_marko;
curwp->w_bufp->b_fcol = curwp->w_fcol;
}
if (lwp == NULL)
wheadp = curwp->w_wndp;
else
lwp->w_wndp = curwp->w_wndp;
free(